// 路由定义
import { RouteRecordRaw } from 'vue-router';

/**
 * @name 常驻路由
 * @description 除了 redirect/403/404/login 等隐藏页面，其他页面设置唯一的 Name 属性
 */
// 1. 常驻路由：所有用户可见
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/login',
    component: () => import('@/pages/Login/index.vue'),
    meta: { hidden: true }, // hidden 通常用于控制菜单是否显示
  },
  {
    path: '/403',
    component: () => import('@/pages/Error/403.vue'),
    meta: { hidden: true },
  },
  {
    path: '/404',
    component: () => import('@/pages/Error/404.vue'),
    meta: { hidden: true },
  },
];

/**
 * @name 动态权限路由
 * @description 动态路由：需要系统级和项目级双重权限控制
 */

export const dynamicRoutes: RouteRecordRaw[] = [
  {
    path: '/home',
    name: 'home',
    component: () => import('@/pages/Home/index.vue'),
    meta: { level: 'system' },
  },
  {
    path: '/project/:id',
    name: 'project',
    component: () => import('@/pages/Project/index.vue'),
    meta: {
      level: 'project',
      permission: 'project:manage',
    },
    // 新增API文档详情路由
    children: [
      {
        path: 'api/:apiId',
        name: 'api-detail',
        component: () => import('@/pages/project/components/ApiDetail.vue'),
        props: (route) => ({
          mode: route.query.mode || 'view',
          apiId: Number(route.params.apiId),
          projectId: Number(route.params.id),
        }),
        meta: {
          level: 'project',
          permission: 'project:manage:api',
        },
      },
    ],
  },

  {
    path: '/project/:id/admin-panel',
    name: 'admin-panel',
    component: () => import('@/pages/AdminPanel/index.vue'),
    meta: {
      level: 'project',
      permission: 'project:manage:center',
    },
    children: [
      {
        path: 'member',
        name: 'member',
        component: () => import('@/pages/AdminPanel/components/Member.vue'),
        meta: {
          level: 'project',
          title: '成员管理',
          icon: `IconMember`,
          permission: 'project:manage:member',
        },
      },
      {
        path: 'permission',
        name: 'permission',
        component: () => import('@/pages/AdminPanel/components/Permission.vue'),
        meta: {
          level: 'project',
          title: '角色权限配置',
          icon: `IconPermission`,
          permission: 'project:manage:role',
        },
      },
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@/pages/AdminPanel/components/DashBoard.vue'),
        meta: {
          level: 'project',
          title: '数据统计',
          icon: `IconDashBoard`,
          permission: 'project:manage:statistic',
        },
      },
      {
        path: 'setting',
        name: 'setting',
        component: () =>
          import('@/pages/AdminPanel/components/ProjectSetting.vue'),
        meta: {
          level: 'project',
          title: '项目设置',
          icon: `IconProjectSetting`,
          permission: 'project:manage:setting',
        },
      },
    ],
  },
];
